package com.real.operationalcontrols.任务;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.real.operationalcontrols.R;
import com.real.operationalcontrols.rxhttp.MyDialogObserver;
import com.real.operationalcontrols.rxhttp.NetworkUrl;
import com.real.operationalcontrols.rxhttp.RxHttpManger;
import com.real.operationalcontrols.基类.BaseActivity;
import com.real.operationalcontrols.实体类.TaskDetialBean;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

public class TaskMainActivity extends BaseActivity {

    @BindView(R.id.bar_back_btn)
    ImageView barBackBtn;
    @BindView(R.id.bar_title)
    TextView barTitle;
    @BindView(R.id.bar_check_btn)
    TextView barCheckBtn;
    @BindView(R.id.task_id)
    TextView taskId;
    @BindView(R.id.task_time)
    TextView taskTime;
    @BindView(R.id.task_address)
    TextView taskAddress;
    @BindView(R.id.task_name)
    TextView taskName;
    @BindView(R.id.task_txt)
    TextView taskTxt;
    @BindView(R.id.task_status)
    TextView taskStatus;
    @BindView(R.id.task_btn)
    TextView taskBtn;
    String id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_task_main);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_task_main;
    }

    @Override
    protected void getData() {
        id = getIntent().getStringExtra("id");
        barTitle.setText("任务详情");
        Map<String, String> map = new HashMap<>();
        map.put("taskname", id);
        RxHttpManger.getInstance().get(this, NetworkUrl.TASK_DETIAL, map,
                new MyDialogObserver(this) {
                    @Override
                    public void onSuccess(String response) {
                        TaskDetialBean bean = new Gson().fromJson(response, TaskDetialBean.class);
                        if (bean.isSuccess()) {
                            taskId.setText(bean.getTasklist().get(0).getId());
                            taskTime.setText(bean.getTasklist().get(0).getTime());
                            taskAddress.setText(bean.getTasklist().get(0).getAddress());
                            taskName.setText(bean.getTasklist().get(0).getPeople());
                            taskStatus.setText(bean.getTasklist().get(0).getStatus());
                            StringBuilder sb = new StringBuilder();
                            for (int i = 0; i < bean.getTasklist().get(0).getContext().size(); i++) {
                                sb.append(bean.getTasklist().get(0).getContext().get(i).getTip()).append("\n");
                            }
                            taskTxt.setText(sb.toString());
                        } else {
                            ToastUtils.showShort(bean.getMessage());
                        }
                    }
                });
    }

    @OnClick({R.id.bar_back_btn, R.id.task_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bar_back_btn:
                finish();
                break;
            case R.id.task_btn:
                Map<String, String> map = new HashMap<>();
                map.put("taskname", id);
                RxHttpManger.getInstance().get(this, NetworkUrl.TASK_STATUS, map,
                        new MyDialogObserver(this) {
                    @Override
                    public void onSuccess(String response) {

                    }
                });
                Intent intent = new Intent(this, TaskInfoActivity.class);
                intent.putExtra("id", id);
                startActivity(intent);
                finish();
                break;
        }
    }
}
